package com.cordova.test.imageselect.module

import android.os.Parcel
import android.os.Parcelable
import java.io.Serializable
import java.util.ArrayList

/**
 *
 * var name: String? = null                  //当前文件夹的名字
 * var path: String? = null                  //当前文件夹的路径
 * var cover: ImageItem? = null              //当前文件夹需要要显示的缩略图，默认为最近的一次图片
 * var images: ArrayList<ImageItem>? = null  //当前文件夹下所有图片的集合
 *
 */
data class ImageFolder(var name: String? = null, var path: String? = null, var cover: ImageItem? = null,
                       var images: ArrayList<ImageItem>? = null) : Parcelable {

    /** 只要文件夹的路径和名字相同，就认为是相同的文件夹  */
    override fun equals(o: Any?): Boolean {
        try {
            val other = o as ImageFolder?
            return this.path.equals(other!!.path, ignoreCase = true) && this.name.equals(other.name, ignoreCase = true)
        } catch (e: ClassCastException) {
            e.printStackTrace()
        }

        return super.equals(o)
    }

    constructor(parcel: Parcel) : this(
            parcel.readString(),
            parcel.readString(),
            parcel.readParcelable(ImageItem::class.java.classLoader),
            TODO("images"))

    override fun writeToParcel(parcel: Parcel, flags: Int) {
        parcel.writeString(name)
        parcel.writeString(path)
        parcel.writeParcelable(cover, flags)
    }

    override fun describeContents(): Int {
        return 0
    }

    companion object CREATOR : Parcelable.Creator<ImageFolder> {
        override fun createFromParcel(parcel: Parcel): ImageFolder {
            return ImageFolder(parcel)
        }

        override fun newArray(size: Int): Array<ImageFolder?> {
            return arrayOfNulls(size)
        }
    }


}